package com.lu.pojo.thread.status;

/**
 * @author luzhenfang
 * @date 2020 05 24
 * @description 线程优先级
 * 优先级高的 线程 通常情况下 优先执行
 */
public class ThreadPriority {
    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getName() + "-->" + Thread.currentThread().getPriority());
        MyPriority myPriority = new MyPriority();
        Thread thread1 = new Thread(myPriority);
        Thread thread2 = new Thread(myPriority);
        Thread thread3 = new Thread(myPriority);
        Thread thread4 = new Thread(myPriority);
        Thread thread5 = new Thread(myPriority);
        Thread thread6 = new Thread(myPriority);
        // 先设置优先级 再启动
        thread1.start();
        thread2.setPriority(1);
        thread2.start();

        thread3.setPriority(4);
        thread3.start();

        // 10
        thread4.setPriority(Thread.MAX_PRIORITY);
        thread4.start();

        /*
        thread5.setPriority(-1);
        thread5.start();

        thread6.setPriority(11);
        thread6.start();

         */
    }
}


class MyPriority implements Runnable {

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "--->" + Thread.currentThread().getPriority());
    }
}
